<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新闻显示页面</title>
    <script src="../../../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
    <link href="../../../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../../../res/echarts/eleTree.js"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../res/images/favicon.ico">
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
    <script>
        $.ajaxSetup({
            async: false
        });
    </script>
</head>
<body>
    <h1 style="text-align: center;font-size: 40px" id="newsTitle">

    </h1>
    <div style="padding-top: 25px;width: 60%;margin: 10px auto" id="newsBrid">

    </div>
    <div id="img" style="padding-top: 25px;width: 60%;margin: 10px auto;text-align: center">
        <img src="" id="newsImg" style="width: 100%">
    </div>
    <div id="newsBody" style="padding-top: 25px;width: 60%;margin: 10px auto" >

    </div>

    <div style="padding-top: 25px;width: 60%;margin: 10px auto;">
        <span>下载附件:</span>
        <button id="btnone"  type="button" onclick="download()" class="layui-btn layui-btn-normal"></button>
        <a style="display: none" id="clickA" target="_blank"></a>
    </div>

    <div  style="padding-top: 25px;width: 60%;margin: 10px auto;display: flex">
        <h3 id="create" style="flex: 1"></h3>
        <h3 id="createTime" style="text-align: right"></h3>
    </div>

</body>
<script>
    var form=null;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        form = layui.form
        //修改操作
        var ide = getQueryString("pkNewsId");
        if(ide) {
            findById();//修改页面的赋值
        }
    });
    function fmtDate(time){
        var date=new Date();
        var data = new Date(time);
        var year = data.getFullYear();  //获取年
        var month = data.getMonth() + 1;    //获取月
        var day = data.getDate(); //获取日
        var hours = data.getHours();
        var minutes = data.getMinutes();
        if (date.getFullYear()==year&&date.getMonth() + 1==month){
            if (date.getDate()==day){
                time = "今天" + " " + hours + ":" + minutes;
                return time;
            }
            if ((parseInt(date.getDate())-1)==day){
                time = "昨天" + " " + hours + ":" + minutes;
                return time;
            }
        }

        time = year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes;
        return time;
    }

        function download(){
            var name=$("#btnone").prop("name")
            $('#clickA').attr('href',name);
            if( $('#clickA').attr('href')){
                document.getElementById('clickA').click();//可以触发超链接a
            }
        }
        function findById(){
            var id=getQueryString("pkNewsId");
            var url="../../../../OaNewsAction/findById/"+id;
            var data=getAjaxById(url);
            var date=fmtDate(data.data.createdTime);
            $("#createTime").html("发布时间:"+ date);
            $("#create").html("发布人:"+data.data.createdBy);
            $("#pkNewsTypeId").html(data.data.pkNewsTypeId);
            $("#newsTitle").html(data.data.newsTitle);
            $("#newsBrid").html(data.data.newsBrid);
            $("#newsBody").html(data.data.newsBody);

            if(data.data.newsFile){
                $("#btnone").prop("name",data.data.newsFile);
                $('#btnone').html("下载附件");
            }else{
                $("#btnone").html("没有上传文档附件");
                $('#btnone').attr('class', 'layui-btn layui-btn-disabled'); //图片链接（base64）
            }
            if(data.data.newsImg){
                $("#img").show();
                $('#newsImg').attr('src', data.data.newsImg); //图片链接（base64）
            }
            form.render('select');
        }
</script>
</body>
</html>